import { useEffect, useState } from "react";

type UserType = {
  name: string;
  age: number;
};

const fetchUserApi = async (): Promise<UserType> => {
  const user = { name: "John Doe", age: 30 };
  //   throw new Error("fetchUserAPI报错");
  return user;
};

function Page5() {
  const [user, setUser] = useState<UserType>();
  useEffect(() => {
    const fetchData = async () => {
      setUser(await fetchUserApi());
    };
    fetchData();
  }, []);

  return (
    <div style={{ backgroundColor: "pink", padding: "20px" }}>
      <div>
        <h3>Page5</h3>
        <p>用户名：{user?.name}</p>
      </div>
    </div>
  );
}

export default Page5;
